import { IFormProps, size, formItemLayout, getUploadResult, getImages, getFileList } from '../../utils/common';
import React from 'react';
import { Modal, Form, Input, Select, Upload, InputNumber } from 'antd';
import * as api from '../../api/api';
import { FormComponentProps } from 'antd/lib/form';
export interface IDividendsEditProps extends FormComponentProps {
    visible: boolean,
    dividend?: api.SingleUserMallDividendsVODividendVO,
    onSave: (any) => void,
    onCancel: () => void,
}
class DividendsEdit extends React.PureComponent<IDividendsEditProps, any>{
    constructor(props) {
        super(props);
    }

    ok = (e) => {
        e.preventDefault();
        this.props.form.validateFieldsAndScroll((err, form) => {
            if (!err) {
                form['dividendAmount'] = form['dividendAmountView']/100;
                this.props.onSave(form);
            }
        });
    }

    cancel = () => {
        this.props.onCancel();
    }

    render(): JSX.Element {
        const { getFieldDecorator } = this.props.form;
        const { dividend } = this.props;
        return (
            <Modal
                title='分红比例'
                visible={this.props.visible}
                onOk={this.ok}
                onCancel={this.cancel}
                maskClosable={true}
            >
                <Form>
                <Form.Item label="期限（月）" {...formItemLayout}>
                        {getFieldDecorator('timelimit', {
                            initialValue: dividend && dividend.timelimit
                        })(<Input size={size}
                            placeholder="请输入期限" />)}
                    </Form.Item>
                    <Form.Item label="期限内分润(%)" {...formItemLayout}>
                        {getFieldDecorator('dividendAmountView', {
                            rules: [
                                {
                                    required: true,
                                    message: '请输入分润百分比'
                                }
                            ],
                            initialValue: dividend && dividend.dividendAmountView
                        })(<Input size={size}
                            placeholder="请输入分润百分比" />)}
                    </Form.Item>
                  
                    <Form.Item label="分红方式" {...formItemLayout}>
                        {getFieldDecorator('presentType', {
                            rules: [
                                {
                                    required: true,
                                    message: '请选择'
                                }
                            ],
                            initialValue: dividend && dividend.dividendTypes ? dividend.dividendTypes: 0
                        })(<Select style={{ width: 120 }}
                            placeholder="请选择"
                        >
                            <Select.Option value={0}>现金</Select.Option>
                        </Select>)}
                    </Form.Item>
                </Form>
            </Modal>)
    }
}

export default Form.create()(DividendsEdit);